package com.ellricky.teacher.ui.mycourse.course

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.andr.common.ui.adapter.BaseViewPagerAdapter
import com.andr.common.ui.fragment.BaseFragment
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.widget.calendar.WeekDateEntity
import com.ellricky.baselib.widget.calendar.WeekDateView
import com.ellricky.teacher.FRAGMENT_COURSE_VIP
import com.ellricky.teacher.R
import kotlinx.android.synthetic.main.tc_fragment_vip_course.*
import java.util.*

class VipCourseFragment : BaseFragment<Void, BasePresenter<Void>>(), WeekDateView.OnSelectListener {


    private lateinit var weekFrgList: ArrayList<Fragment>
    private var curWeekDate: String? = null

    override fun getContentLayout() = R.layout.tc_fragment_vip_course

    companion object {
        fun newInstance(pageType: Int): VipCourseFragment {
            val fragment = VipCourseFragment()
            val bundle = Bundle()
            bundle.putInt("pageType", pageType)
            fragment.arguments = bundle
            return fragment
        }
    }


    override fun initUIView(root: View?) {

        weekFrgList = ArrayList()
        for (i in 0..6) {
            val frg = CourseFragment.newInstance(FRAGMENT_COURSE_VIP)
            weekFrgList.add(frg)
        }

        vpCourse.adapter = BaseViewPagerAdapter(childFragmentManager, weekFrgList)

        weekDateView.setOnSelectListener(this)
        weekDateView.getData("", false)

        tvSeeWeekCourse.setOnClickListener(this)
    }


    override fun onClickView(view: View?) {
        super.onClickView(view)
        when (view) {
            tvSeeWeekCourse -> EAppUtil.jumpPageWithNoParam(this, WeekCourseListActivity::class.java)
        }

    }

    override fun onSelected(position: Int, dateEntity: WeekDateEntity?) {
        vpCourse.currentItem = position

        curWeekDate = dateEntity?.date
        tvDayDate.text = curWeekDate
        val fragment = weekFrgList[position] as CourseFragment
        fragment.setWeekDate(curWeekDate)
    }

    override fun onChangeWeek(position: Int) {
        val fragment = weekFrgList[position] as CourseFragment
        fragment.setWeekDate(curWeekDate)
        fragment.postRequest()
    }



}
